//
//  BaseViewContoller.swift
//  Stauts
//
//  Created by Kylin on 16/3/13.
//  Copyright © 2016年 Kylin. All rights reserved.
//

import UIKit

class BaseViewContoller: UITableViewController {

    // MARK:- 懒加载
    lazy var visitorView : VisitorView = VisitorView.visitorView()
    
    // MARK:- 属性
    var isLogin : Bool = UserAccountViewModel.shareManager.isLogin
    
    // 系统回调函数 根据状态加载不周的view
    override func loadView() {
        isLogin ? super.loadView() : setupVisitorView()
    }
}
extension BaseViewContoller {
    /// 加载访客视图
    private func setupVisitorView () {
        
        //1:访客视图
        view = visitorView
        
        //2:添加导航栏左右的Item
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: #selector(BaseViewContoller.registerBunClick))
         navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: .Plain, target: self, action: #selector(BaseViewContoller.loginBunClick))
        
      // 3.监听访客视图中注册和登录按钮的点击
        visitorView.registerBtn.addTarget(self, action: #selector(BaseViewContoller.registerBunClick), forControlEvents: .TouchUpInside)
        visitorView.loginBtn.addTarget(self, action: #selector(BaseViewContoller.loginBunClick), forControlEvents: .TouchUpInside)
    }
}

extension BaseViewContoller {
    @objc private func registerBunClick () {
        print("registerBunClick")
    }
    
    @objc private func loginBunClick () {
        // 创建授权介面
        let OAuthVc = OAuthViewController()
        
        // 包装成导航控制器
        let OAuthNav = UINavigationController(rootViewController: OAuthVc)
        
        // 弹出授权介面
        presentViewController(OAuthNav, animated: true, completion: nil)
    }
}